<?php

class Application_Form_FolhaPonto extends Zend_Form
{

    public function init()
    {
        $this->addElementPrefixPath('Tri_Filter', 'Tri/Filter', 'FILTER');
        $this->addElementPrefixPath('Tri_Validate', 'Tri/Validate', 'VALIDATE');
        
        $this->clearDecorators();
        $decorators = array(
            array('ViewHelper'),
            array('Errors'),
            array('Label',array(
                'class' => 'leftalign'
            )),
            array('HtmlTag',array('tag' => 'li'))
        );

        $folha = new Tri_Db_Table('folha_ponto');

        $validators = $folha->getValidators();
        $filters    = $folha->getFilters();

        $this->setAction('folha-ponto/save')
                ->setMethod('post')
                ->setAttrib('enctype', 'multipart/form-data');

        $id = new Zend_Form_Element_Hidden('id');
        $id->addValidators($validators['id'])
                ->addFilters($filters['id'])
                ->setDecorators(array('ViewHelper'));
        
        $table = new Tri_Db_Table('usuario');
        $lista_usuarios = $table->fetchPairs('id', 'nome');
        
        $user_id = new Zend_Form_Element_Select('user_id');
        $user_id->setLabel('Nome')
                ->addMultiOptions($lista_usuarios)
                ->setAttribs(array('class' => 'span4'))
                ->setDecorators($decorators); 
  
        $meses = array(
            NULL => 'Selecione',
            1 => 'JANEIRO',
            2 => 'FEVEREIRO',
            3 => 'MARÇO',
            4 => 'ABRIL',
            5 => 'MAIO',
            6 => 'JUNHO',
            7 => 'JULHO',
            8 => 'AGOSTO',
            9 => 'SETEMBRO',
            10 => 'OUTUBRO',
            11 => 'NOVEMBRO',
            12 => 'DEZEMBRO'
            );
        $mes = new Zend_Form_Element_Select('mes');
        $mes->setLabel('Mês')
                ->addMultiOptions($meses)
                ->setValue((int)date('m',time()))
                ->setRequired()
                ->setAttribs(array(
                    'class' => 'span2',
                    ))
                ->setDecorators($decorators); 

        $anos = array(
            2010 => '2010',
            2011 => '2011',
            2012 => '2012',
            2013 => '2013',
            2014 => '2014',
            2015 => '2015',
            );
        $ano = new Zend_Form_Element_Select('ano');
        $ano->setLabel('Ano')
                ->addMultiOptions($anos)
                ->setValue((int)date('Y',time()))
                ->setRequired()
                ->setAttribs(array(
                    'style' => 'width:80px',
                    ))
                ->setDecorators($decorators); 


        $horas_acumuladas = new Zend_Form_Element_Text('horas_acumuladas');
        $horas_acumuladas->setLabel('Horas Acumuladas')
                ->addValidators($validators['horas_acumuladas'])
                ->addFilters($filters['horas_acumuladas'])
                ->setRequired()
                ->setAttribs(array(
                    'class' => 'span1',
                    ))
                ->setDecorators($decorators); 


        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Salvar')
                ->setAttribs(array(
                    'style' => 'margin: 20px 0 0 210px;',
                    'class' => 'btn primary'))
                ->setDecorators(array(
            array('ViewHelper'),
            array('HtmlTag',
                array(
                'tag' => 'li',
                'class' => 'submit'))
        ));

        $this->setDecorators(array(
           'FormElements',
            array('HtmlTag',array('tag'=>'ul')),
            array(
                array(
                    'DivTag'=>'HtmlTag'
                ),
                array(
                    'tag'=>'div',
                    'class'=>'FormDiv'
                )
            ),
            'Form'
        ));

        
        $this->addElement($id)
             ->addElement($user_id)
             ->addElement($mes)
             ->addElement($ano)
             ->addElement($horas_acumuladas)
             ->addElement($submit);
//             ->addDisplayGroup(array('submit', 'voltar'), 'buttons', 
//                     array(
//                        'decorators' => array(
//                            'FormElements',
//                            array('HtmlTag', array('tag' => 'div', 'class' => 'form-actions'))
//            )));

        
    }
    

}
